package com.zhihuanbao.business.sys.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zhihuanbao.business.domain.BizIndustryCode;
import com.zhihuanbao.business.service.IBizIndustryCodeService;
import com.zhihuanbao.common.core.domain.entity.SysDept;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhihuanbao.common.annotation.Log;
import com.zhihuanbao.common.core.controller.BaseController;
import com.zhihuanbao.common.core.domain.AjaxResult;
import com.zhihuanbao.common.enums.BusinessType;
import com.zhihuanbao.common.utils.poi.ExcelUtil;
import com.zhihuanbao.common.core.page.TableDataInfo;

/**
 * 行业代码Controller
 * 
 * @author zhihuanbao
 * @date 2024-06-11
 */
@Api("行业代码信息管理")
@RestController
@RequestMapping("/business/industry")
public class BizIndustryCodeController extends BaseController
{
    @Autowired
    private IBizIndustryCodeService bizIndustryCodeService;

    /**
     * 查询行业代码列表
     */
    @ApiOperation("获取所有行业代码")
    @PreAuthorize("@ss.hasPermi('business:industry:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizIndustryCode bizIndustryCode)
    {
        startPage();
        List<BizIndustryCode> list = bizIndustryCodeService.selectBizIndustryCodeList(bizIndustryCode);
        return getDataTable(list);
    }

    /**
     * 导出行业代码列表
     */
    @PreAuthorize("@ss.hasPermi('business:industry:export')")
    @Log(title = "行业代码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizIndustryCode bizIndustryCode)
    {
        List<BizIndustryCode> list = bizIndustryCodeService.selectBizIndustryCodeList(bizIndustryCode);
        ExcelUtil<BizIndustryCode> util = new ExcelUtil<BizIndustryCode>(BizIndustryCode.class);
        util.exportExcel(response, list, "行业代码数据");
    }

    /**
     * 获取行业代码详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:industry:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizIndustryCodeService.selectBizIndustryCodeById(id));
    }

    /**
     * 新增行业代码
     */
    @PreAuthorize("@ss.hasPermi('business:industry:add')")
    @Log(title = "行业代码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizIndustryCode bizIndustryCode)
    {
        return toAjax(bizIndustryCodeService.insertBizIndustryCode(bizIndustryCode));
    }

    /**
     * 修改行业代码
     */
    @PreAuthorize("@ss.hasPermi('business:industry:edit')")
    @Log(title = "行业代码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizIndustryCode bizIndustryCode)
    {
        return toAjax(bizIndustryCodeService.updateBizIndustryCode(bizIndustryCode));
    }

    /**
     * 删除行业代码
     */
    @PreAuthorize("@ss.hasPermi('business:industry:remove')")
    @Log(title = "行业代码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizIndustryCodeService.deleteBizIndustryCodeByIds(ids));
    }

    /**
     * 获取代码分类信息
     */
    @ApiOperation("获取行业代码分类信息")
    @PreAuthorize("@ss.hasPermi('business:industry:query')")
    @GetMapping(value = "/code/{type}")
    public TableDataInfo findByCodeType(@PathVariable("type") String type)
    {
        startPage();
        List<BizIndustryCode> list = bizIndustryCodeService.selectBizIndustryCodeListByCodeType(type);
        return getDataTable(list);
    }

    @ApiOperation("获取分页行业代码分类信息")
    @ApiImplicitParam(name = "parentId", value = "编号父ID", defaultValue = "0", required = true, dataType = "long", paramType = "path", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermi('business:industry:query')")
    @GetMapping(value = "/page/parent/{parentId}")
    public TableDataInfo findPageByParentId(@PathVariable("parentId") Long parentId)
    {
        startPage();
        List<BizIndustryCode> list = bizIndustryCodeService.selectBizIndustryCodeListByPatentId(parentId);
        return getDataTable(list);
    }

    /**
     * 获取行业代码树：不推荐使用，影响性能
     */
    @ApiOperation("获取行业代码分类信息")
    @ApiImplicitParam(name = "parentId", value = "编号父ID", defaultValue = "0", required = true, dataType = "long", paramType = "path", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermi('business:industry:query')")
    @GetMapping(value = "/parent/{parentId}")
    public AjaxResult findByParentId(@PathVariable("parentId") Long parentId)
    {
        List<BizIndustryCode> industryList = bizIndustryCodeService.selectBizIndustryCodeListByPatentId(parentId);
        return success(industryList);
    }
    /**
     * 获取行业代码树：不推荐使用，影响性能
     */
//    @PreAuthorize("@ss.hasPermi('system:dept:list')")
//    @GetMapping("/tree")
//    public AjaxResult tree(BizIndustryCode industry)
//    {
//        List<BizIndustryCode> industryList = bizIndustryCodeService.selectIndustryCodeTree(industry);
//        return success(industryList);
//    }

}
